import * as userModel from '../../models/user';
import { ValidException, EmptyException, SystemException } from '../../helps/exception';

export function* list({ page, number, order, direction }) {
  return yield userModel.list(page, number, order, direction);
}

export function* get({ user_id }) {
  if (!user_id) throw ValidException('id 不能为空');
  const user = yield userModel.get(user_id);
  if (!user) throw EmptyException('无相关信息');
  return user;
}

export function* put({ user_id, data }) {
  if (!user_id) throw ValidException('id 不能为空');
  const b = yield userModel.put(user_id, data);
  if (!b) throw SystemException('操作失败');
  return { id: user_id };
}
